﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Client.model
{
    public class Table
    {
        byte[] flat1;
        byte[] flat2;
        byte[] flat3;
        byte[] slop1;
        byte[] slop2;
        byte[] slop3;
        byte[][] tables;
        
        int row;
        int column;
        int leftTable=0;
        int rightTable=1;
        

        public Table() {
            flat1 = ParsingMap(Client.Properties.Resources.flat1);
            flat2 = ParsingMap(Client.Properties.Resources.flat2);
            flat3 = ParsingMap(Client.Properties.Resources.flat3);
            slop1 = ParsingMap(Client.Properties.Resources.slop1);
            slop2 = ParsingMap(Client.Properties.Resources.slop2);
            slop3 = ParsingMap(Client.Properties.Resources.slop3);
            tables = new byte[][] { flat1, flat2, flat3, slop1, slop2, slop3};
        }

        public int[] getColumn(int index, int col)
        {
            byte[] table = tables[index];
            int[] columns = new int[row];
            for (int i = 0; i < row; i++) {
                columns[i] = table[i * column + col];
            }
            return columns;
        }

        byte[] ParsingMap(string colormap)
        {
            string[] lines = colormap.Split('\n');
            row = lines.Length;
            column = lines[0].Split('\t').Length;
            byte[] data = new byte[lines.Length * lines[0].Split('\t').Length];

            for (int i = 0; i < lines.Length; i++)
            {
                string line = lines[i];
                string[] values = line.Split('\t');

                for (int j = 0; j < values.Length; j++)
                    data[i * values.Length + j] = Convert.ToByte(values[j]);
            }
            return data;
        }

        public byte[][] Tables
        {
            get { return tables; }
            set { tables = value; }
        }

        public byte[] Flat1
        {
            get { return flat1; }
            set { flat1 = value; }
        }
        public byte[] Flat2
        {
            get { return flat2; }
            set { flat2 = value; }
        }

        public byte[] Flat3
        {
            get { return flat3; }
            set { flat3 = value; }
        }

        public byte[] Slop1
        {
            get { return slop1; }
            set { slop1 = value; }
        }

        public byte[] Slop2
        {
            get { return slop2; }
            set { slop2 = value; }
        }

        public byte[] Slop3
        {
            get { return slop3; }
            set { slop3 = value; }
        }
        public int LeftTable
        {
            get { return leftTable; }
            set { leftTable = value; }
        }

        public int RightTable
        {
            get { return rightTable; }
            set { rightTable = value; }
        }
       
    }
}
